package datastructure;

/**
 * @Author: DRevelation
 * @Date: 2021/1/27 15:10
 */
public class MyLinkedList {

    public static Node head = new Node();

    public static void addData(int value) {
        Node newNoe = new Node(value);
        Node temp = head;
        while (temp.next != null) {
            temp = temp.next;
        }
        temp.next = newNoe;
    }

    public static void traverse(Node head) {
        Node temp = head.next;
        while (temp != null) {
            System.out.println("data = " + temp.data);
            temp = temp.next;
        }
    }

    public static void main(String[] args) {
        addData(1);
        addData(2);
        addData(3);
        addData(4);
        traverse(head);
    }

}

class Node {
    /**
     * 数据域
     */
    public int data;

    /**
     * 指针域
     */
    public Node next;

    public Node() {}

    public Node(int data) {
        this.data = data;
    }

    public Node(int data, Node next) {
        this.data = data;
        this.next = next;
    }
}
